//
//  EnteringViewController.m
//  AIM
//
//  Created by user10 on 2017/5/17.
//  Copyright © 2017年 user10. All rights reserved.
//

#import "EnteringViewController.h"
#import "AreaTableViewController.h"
#import "PostViewController.h"
#import "TagTableViewController.h"
#import "typeTableViewController.h"
#import "NetWorkTools.h"
#import <UIImageView+WebCache.h>
#import "logModel.h"
#import "DataBase.h"

@interface EnteringViewController ()<typeTableViewDelegate,TagTableViewDelegate,AreaTableViewDelegate,PostViewViewDelegate>
@property (nonatomic, strong)NSString *typeStr;
@property (nonatomic, strong)NSMutableArray *tagArr;
@property (nonatomic, strong)NSMutableArray *areaArr;
@property (nonatomic, weak)UIScrollView *scrollView;
@property (nonatomic, strong)NSString *historyTypeStr;
@property (nonatomic, strong)NSMutableArray *histroyTagArr;
@property (nonatomic, strong)NSMutableArray *histroyAreaArr;


@end

@implementation EnteringViewController

- (void)viewDidLoad {
    self.automaticallyAdjustsScrollViewInsets = NO;
    [super viewDidLoad];
    
    //初始化导航条
    [self setupNav];
    if (_messageId.length != 0) {
        [self loadEnterData];
    }else{
        //初始化scrollView及其子控制器
        [self setupScrollView];
    }
    _tagArr = [NSMutableArray array];
    
    _areaArr = [NSMutableArray array];
    
    _histroyTagArr = [NSMutableArray array];
    
    _histroyAreaArr = [NSMutableArray array];
    
}

- (void)loadEnterData{
    float width = [UIScreen mainScreen].bounds.size.width;
    float height = [UIScreen mainScreen].bounds.size.height - 64;
    //初始化容器视图控制器
    UIScrollView * scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, width, height)];
    scrollView.contentSize = CGSizeMake(4 * width, height);
    scrollView.backgroundColor = [UIColor whiteColor];
    scrollView.bounces = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
    
    [self.view addSubview:scrollView];
    _scrollView = scrollView;
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if(status ==AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi)
        {
            NSString *webServiceStr = [NSString stringWithFormat:
                                       @"<web:getMessageToData>\
                                       <arg0>%@</arg0>\
                                       <arg1>%@</arg1>\
                                       </web:getMessageToData>",COMPANY,_messageId];
            
            NetWorkTools *tools = [NetWorkTools shareTools];
            [tools request:POST urlString:[NSString stringWithFormat:@"http://%@:8888/webservice/ws/PostToImplPort?wsdl",[NSUD objectForKey:@"URL"]] parametersStr:webServiceStr finished:^(id responseObject, NSError *error) {
                NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
                NSString *string = result;
                if (result.length != 0) {
                    NSRange startRange = [string rangeOfString:@"@@"];
                    NSRange endRange = [string rangeOfString:@"</return>"];
                    NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
                    if (range.location != NSNotFound) {
                        NSString *resultString = [string substringWithRange:range];
                        NSData * getJsonData = [resultString dataUsingEncoding:NSUTF8StringEncoding];
                        NSDictionary * getDict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:&error];
                        [_histroyAreaArr addObjectsFromArray:[getDict objectForKey:@"MSG_DATA_LIST"]];
                        //初始化area视图控制器
                        AreaTableViewController *areaVc = [[AreaTableViewController alloc]init];
                        areaVc.historyArr = _histroyAreaArr;
                        areaVc.view.frame = CGRectMake(width, 20, width, height);
                        UILabel *areaL = [[UILabel alloc]init];
                        areaVc.areaDelegate = self;
                        areaL.frame = CGRectMake(width, 0, width, 20);
                        areaL.text = @"To";
                        areaL.textColor = [UIColor blackColor];
                        areaL.textAlignment = NSTextAlignmentLeft;
                        [scrollView addSubview:areaL];
                        [scrollView addSubview:areaVc.view];
                        [self addChildViewController:areaVc];
                    }else{
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Network error" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
                        alert.delegate = self;
                        [alert show];
                    }
                }
            }];
            
            
            NSString *webServiceStr1 = [NSString stringWithFormat:
                                        @"<web:getMessageCategoryData>\
                                        <arg0>%@</arg0>\
                                        <arg1>%@</arg1>\
                                        </web:getMessageCategoryData>",COMPANY,_messageId];
            
            NetWorkTools *tools1 = [NetWorkTools shareTools];
            [tools1 request:POST urlString:[NSString stringWithFormat:@"http://%@:8888/webservice/ws/PostCategoryImplPort?wsdl",[NSUD objectForKey:@"URL"]] parametersStr:webServiceStr1 finished:^(id responseObject, NSError *error) {
                NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
                NSString *string = result;
                if (result.length != 0) {
                    NSRange startRange = [string rangeOfString:@"@@"];
                    NSRange endRange = [string rangeOfString:@"</return>"];
                    NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
                    if (range.location != NSNotFound) {
                        NSString *resultString = [string substringWithRange:range];
                        NSData * getJsonData = [resultString dataUsingEncoding:NSUTF8StringEncoding];
                        NSDictionary * getDict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:&error];
                        _historyTypeStr = [getDict objectForKey:@"MSG_CATEGORY_CD"];
                        //初始化type视图控制器
                        typeTableViewController *typeVc = [[typeTableViewController alloc]init];
                        typeVc.histroyStr = _historyTypeStr;
                        [self addChildViewController:typeVc];
                        typeVc.typeDelegate = self;
                        UILabel *typeL = [[UILabel alloc]init];
                        typeL.frame = CGRectMake(0 * width, 0, width, 20);
                        typeL.text = @"Category & Sub Category";
                        typeL.textColor = [UIColor blackColor];
                        typeL.textAlignment = NSTextAlignmentLeft;
                        typeVc.view.frame = CGRectMake(0, 20, width, height);
                        [scrollView addSubview:typeL];
                        [scrollView addSubview:typeVc.view];
                    }else{
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Network error" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
                        alert.delegate = self;
                        [alert show];
                    }
                }
            }];
            
            NSString *webServiceStr2 = [NSString stringWithFormat:
                                        @"<web:getMessageTagData>\
                                        <arg0>%@</arg0>\
                                        <arg1>%@</arg1>\
                                        </web:getMessageTagData>",COMPANY,_messageId];
            
            NetWorkTools *tools2 = [NetWorkTools shareTools];
            [tools2 request:POST urlString:[NSString stringWithFormat:@"http://%@:8888/webservice/ws/PostTagImplPort?wsdl",[NSUD objectForKey:@"URL"]] parametersStr:webServiceStr2 finished:^(id responseObject, NSError *error) {
                NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
                NSString *string = result;
                if (result.length != 0) {
                    NSRange startRange = [string rangeOfString:@"@@"];
                    NSRange endRange = [string rangeOfString:@"</return>"];
                    NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
                    if (range.location != NSNotFound) {
                        NSString *resultString = [string substringWithRange:range];
                        NSData * getJsonData = [resultString dataUsingEncoding:NSUTF8StringEncoding];
                        NSDictionary * getDict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:&error];
                        [_histroyTagArr addObjectsFromArray:[getDict objectForKey:@"MSG_DATA_LIST"]];
                        //初始化tag视图控制器
                        TagTableViewController *tagVc = [[TagTableViewController alloc]init];
                        tagVc.historyArr = _histroyTagArr;
                        [self addChildViewController:tagVc];
                        tagVc.tagDelegate = self;
                        UILabel *tagL = [[UILabel alloc]init];
                        tagL.frame = CGRectMake(2 * width, 0, width, 20);
                        tagL.text = @"TAG";
                        tagL.textColor = [UIColor blackColor];
                        tagL.textAlignment = NSTextAlignmentLeft;
                        tagVc.view.frame = CGRectMake(2 * width, 20, width, height);
                        [scrollView addSubview:tagL];
                        [scrollView addSubview:tagVc.view];
                    }else{
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Network error" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
                        alert.delegate = self;
                        [alert show];
                    }
                }
            }];
            
            NSString *webServiceStr4 = [NSString stringWithFormat:
                                       @"<web:getPostTextData>\
                                       <arg0>%@</arg0>\
                                       <arg1>%@</arg1>\
                                       </web:getPostTextData>",COMPANY,_messageId];
            
            NetWorkTools *tools4 = [NetWorkTools shareTools];
            
            [tools4 request:POST urlString:[NSString stringWithFormat:@"http://%@:8888/webservice/ws/PostTextImplPort?wsdl",[NSUD objectForKey:@"URL"]] parametersStr:webServiceStr4 finished:^(id responseObject, NSError *error) {
                NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
                NSString *string = result;
                NSRange startRange = [string rangeOfString:@"@@"];
                NSRange endRange = [string rangeOfString:@"</return>"];
                NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
                if (range.location != NSNotFound) {
                    NSString *resultString = [string substringWithRange:range];
                    
                    NSData * getJsonData = [resultString dataUsingEncoding:NSUTF8StringEncoding];
                    NSDictionary * getDict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:&error];
                    
                    PostViewController *postVc = [[PostViewController alloc]init];
                    postVc.view.frame = CGRectMake(3 * width, 20, width, height);
                    postVc.postDelegate = self;
                    postVc.messageId = _messageId;
                    UILabel *postL = [[UILabel alloc]init];
                    postL.frame = CGRectMake(3 * width, 0, width, 20);
                    postL.text = @"POST TITLE";
                    postL.textColor = [UIColor blackColor];
                    postL.textAlignment = NSTextAlignmentLeft;
                    [scrollView addSubview:postL];
                    [scrollView addSubview:postVc.view];
                    postVc.dataType = [getDict objectForKey:@"MSG_DATA_TYPE"];
                    postVc.titleTextFiled.text = [getDict objectForKey:@"MSG_TITLE"];
                    postVc.detailTextFiled.text = [getDict objectForKey:@"MSG_MEMO"];
                    if (postVc.detailTextFiled.text.length != 0) {
                        postVc.placeholderL.hidden =YES;
                    }else{
                        postVc.placeholderL.hidden =NO;
                    }
                    NSMutableArray *MSG_PRODUCTS = [NSMutableArray array];
                    MSG_PRODUCTS = [getDict objectForKey:@"MSG_PRODUCTS"];
                    if (MSG_PRODUCTS.count != 0) {
                        postVc.productTextFiled.text = MSG_PRODUCTS[0];
                    }
                    NSLog(@"%@",getDict);
                    if ([[getDict objectForKey:@"MSG_DATA_TYPE"]isEqualToString:@"IMAGE"]) {
                        postVc.dataType = [getDict objectForKey:@"MSG_DATA_TYPE"];
                        postVc.dataName = [self getNameBaseCurrentTime:@".png"];
                        //                postVc.dataString = [getDict objectForKey:@"MSG_FILE"];
                        [postVc.image sd_setImageWithURL:[getDict objectForKey:@"MSG_IMAGE"]];
                        NSURL *url = [NSURL URLWithString:[getDict objectForKey:@"MSG_IMAGE"]];
                        NSData *imageData = [NSData dataWithContentsOfURL:url];
                        NSString *base64String = [imageData base64EncodedStringWithOptions:0];
                        postVc.dataString = base64String;
                    }else if ([[getDict objectForKey:@"MSG_DATA_TYPE"]isEqualToString:@"VIDEO"]){
                        postVc.dataType = [getDict objectForKey:@"MSG_DATA_TYPE"];
                        postVc.dataName = [self getNameBaseCurrentTime:@".mov"];
                        [postVc.image sd_setImageWithURL:[getDict objectForKey:@"MSG_IMAGE"]];
                        
                        NSURL *url = [NSURL URLWithString:[getDict objectForKey:@"MSG_FILE"]];
                        NSData *data = [NSData dataWithContentsOfURL:url];
                        NSString *base64String = [data base64EncodedStringWithOptions:0];
                        postVc.dataString = base64String;
                    }else if ([[getDict objectForKey:@"MSG_DATA_TYPE"]isEqualToString:@"AUDIO"]){
                        postVc.dataType = [getDict objectForKey:@"MSG_DATA_TYPE"];
                        postVc.dataName = [self getNameBaseCurrentTime:@".mp3"];
                        postVc.image.image = [UIImage imageNamed:@"play_r6"];
                        NSURL *url = [NSURL URLWithString:[getDict objectForKey:@"MSG_FILE"]];
                        NSData *data = [NSData dataWithContentsOfURL:url];
                        NSString *base64String = [data base64EncodedStringWithOptions:0];
                        postVc.dataString = base64String;
                    }
                    
                    [self addChildViewController:postVc];
                }else{
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Network error" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
                    alert.delegate = self;
                    [alert show];
                }
            }];
        }else
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"There is no network" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
            alert.delegate = self;
            [alert show];
        }
    }];
}

- (void)right{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupScrollView{
    
    float width = [UIScreen mainScreen].bounds.size.width;
    float height = [UIScreen mainScreen].bounds.size.height - 64;
    //初始化容器视图控制器
    UIScrollView * scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, width, height)];
    scrollView.contentSize = CGSizeMake(4 * width, height);
    scrollView.backgroundColor = [UIColor whiteColor];
    scrollView.bounces = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
    
    [self.view addSubview:scrollView];
    _scrollView = scrollView;
    
    //初始化area视图控制器
    AreaTableViewController *areaVc = [[AreaTableViewController alloc]init];
    areaVc.view.frame = CGRectMake(width, 20, width, height);
    UILabel *areaL = [[UILabel alloc]init];
    areaVc.areaDelegate = self;
    areaL.frame = CGRectMake(width, 0, width, 20);
    areaL.text = @"To";
    areaL.textColor = [UIColor blackColor];
    areaL.textAlignment = NSTextAlignmentLeft;
    [scrollView addSubview:areaL];
    [scrollView addSubview:areaVc.view];
    [self addChildViewController:areaVc];
    
    //初始化post视图控制器
    PostViewController *postVc = [[PostViewController alloc]init];
    postVc.view.frame = CGRectMake(3 * width, 20, width, height);
    postVc.postDelegate = self;
    UILabel *postL = [[UILabel alloc]init];
    postL.frame = CGRectMake(3 * width, 0, width, 20);
    postL.text = @"POST TITLE";
    postL.textColor = [UIColor blackColor];
    postL.textAlignment = NSTextAlignmentLeft;
    [scrollView addSubview:postL];
    [scrollView addSubview:postVc.view];
    [self addChildViewController:postVc];
    
    //初始化tag视图控制器
    TagTableViewController *tagVc = [[TagTableViewController alloc]init];
    [self addChildViewController:tagVc];
    tagVc.tagDelegate = self;
    UILabel *tagL = [[UILabel alloc]init];
    tagL.frame = CGRectMake(2 * width, 0, width, 20);
    tagL.text = @"TAG";
    tagL.textColor = [UIColor blackColor];
    tagL.textAlignment = NSTextAlignmentLeft;
    tagVc.view.frame = CGRectMake(2 * width, 20, width, height);
    [scrollView addSubview:tagL];
    [scrollView addSubview:tagVc.view];
    
    //初始化type视图控制器
    typeTableViewController *typeVc = [[typeTableViewController alloc]init];
    [self addChildViewController:typeVc];
    typeVc.typeDelegate = self;
    UILabel *typeL = [[UILabel alloc]init];
    typeL.frame = CGRectMake(0 * width, 0, width, 20);
    typeL.text = @"Category & Sub Category";
    typeL.textColor = [UIColor blackColor];
    typeL.textAlignment = NSTextAlignmentLeft;
    typeVc.view.frame = CGRectMake(0, 20, width, height);
    [scrollView addSubview:typeL];
    [scrollView addSubview:typeVc.view];
    
}

- (void)setupNav{
    
    //导航栏中间的label
    UILabel *titleL = [[UILabel alloc]init];
    titleL.text = @"POST";
    titleL.textColor = [UIColor purpleColor];
    [titleL sizeToFit];
    self.navigationItem.titleView = titleL;
    //导航栏右侧按钮
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    closeBtn.frame = CGRectMake(0, 0, 30, 30);
    [closeBtn setBackgroundImage:[UIImage imageNamed:@"post_cross"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(right) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.hidesBackButton = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:closeBtn];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillDisappear:animated];
}
//传值代理
- (void)typeValuesWithStr:(NSString *)typeStr{
    _typeStr = typeStr;
}
- (void)tagValuesWithDict:(NSMutableDictionary *)tagDict{
    [_tagArr addObject:tagDict];
}
- (void)tagValuesDelFromDict:(NSMutableDictionary *)tagDict{
    [_tagArr removeObject:tagDict];
}
- (void)areaValuesWithDict:(NSMutableDictionary *)areaDict{
    [_areaArr addObject:areaDict];
}
- (void)areaValuesDelFromDict:(NSMutableDictionary *)areaDict{
    [_areaArr removeObject:areaDict];
}
#warning 数据处理
- (void)areaValuesWithDictArray:(NSArray *)areaDictArray {
    [_areaArr addObjectsFromArray:areaDictArray];
}

- (void)areaValuesDelFromDictArray:(NSArray *)areaDictArray {
    [_areaArr removeObjectsInArray:areaDictArray];
}

-(void)postValuesWithTitleStr:(NSString *)titleStr detailStr:(NSString *)detailStr productNum:(NSString *)productNum data:(NSString *)dataStr type:(NSString *)type dataName:(NSString *)dataName{
    float width = [UIScreen mainScreen].bounds.size.width;
    
    if (_typeStr == nil) {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Reminder" message:@"category Is not empty" delegate:self cancelButtonTitle:@"YES" otherButtonTitles:nil, nil];
        [alert show];
        [_scrollView setContentOffset:CGPointMake(0,0) animated:YES];
        return;
    }
    if ([_areaArr  isEqual: @[]]) {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Reminder" message:@"area Is not empty" delegate:self cancelButtonTitle:@"YES" otherButtonTitles:nil, nil];
        [alert show];
        
        [_scrollView setContentOffset:CGPointMake(width,0) animated:YES];
        return;
    }
    if ([_areaArr isEqual: @[]]) {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Reminder" message:@"area is not empty" delegate:self cancelButtonTitle:@"YES" otherButtonTitles:nil, nil];
        [alert show];
        [_scrollView setContentOffset:CGPointMake(width,0) animated:YES];
    }
//    if ([_tagArr  isEqual: @[]]) {
//        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"tag不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//        [alert show];
//        
//        [_scrollView setContentOffset:CGPointMake(width * 2,0) animated:YES];
//        return;
//    }
    NSUserDefaults *user  = [NSUserDefaults standardUserDefaults];
    NSString *userStr = [user objectForKey:@"TANTO_CD"];
    
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setObject:userStr forKey:@"SHARE_TANTO_CD"];
    [dict setObject:COMPANY forKey:@"SHARE_COMPANY_CD"];
    [dict setObject:_typeStr forKey:@"SHARE_CATEGORY"];
    [dict setObject:@"A001" forKey:@"SHARE_SHOP_CD"];
    [dict setObject:_areaArr forKey:@"SHARE_TO"];
    [dict setObject:_tagArr forKey:@"SHARE_TAG"];
    [dict setObject:titleStr forKey:@"SHARE_TEXT_TITLE"];
    [dict setObject:detailStr forKey:@"SHARE_TEXT_MEMO"];
    [dict setObject:productNum forKey:@"SHARE_TEXT_PRODUCT_NO"];
    [dict setObject:dataName forKey:@"SHARE_TEXT_FILE_NAME"];
    [dict setObject:dataStr forKey:@"SHARE_TEXT_BIN_DATA"];
    [dict setObject:type forKey:@"SHARE_TEXT_STYLE"];
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    
    NSString *tempStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    NSString *webServiceStr = [NSString stringWithFormat:
                               @"<web:insertPostData>\
                               <arg0>%@</arg0>\
                               </web:insertPostData>",tempStr];
    //初始化网络工具类
    NetWorkTools *tools = [NetWorkTools shareTools];
    //发送网络请求
    [tools request:POST urlString:[NSString stringWithFormat:@"http://%@:8888/webservice/ws/PostImplPort?wsdl",[NSUD objectForKey:@"URL"]] parametersStr:webServiceStr finished:^(id responseObject, NSError *error) {
        NSLog(@"%@---%@",error, type);
        
        NSDate *date = [NSDate date]; // 获得时间对象
        
        NSDateFormatter *forMatter = [[NSDateFormatter alloc] init];
        
        [forMatter setDateFormat:@"yyyy-MM-dd HH-mm-ss"];
        
        NSString *dateStr = [forMatter stringFromDate:date];
        
        logModel *log = [[logModel alloc]init];
        log.time = dateStr;
        log.opration = @"POST success";
        log.type = type;
        log.filename = dataName;
        
        [[DataBase sharedDataBase]addLogModel:log];
        [self.navigationController popViewControllerAnimated:YES];
        if ([self.EnteringDelegate respondsToSelector:@selector(refreshOnce)]) {
            // 调用代理对象的刷新方法，代理对象去实现方法
            [self.EnteringDelegate refreshOnce];
        }
    }];
}

#pragma mark ————————— 以当前时间合成视频名称 —————————————
- (NSString *)getNameBaseCurrentTime:(NSString *)type{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
    return [[dateFormatter stringFromDate:[NSDate date]] stringByAppendingString:type];
}

@end
